package com.yonyougov.devops.cruxcisupport.userrole;

import com.yonyougov.devops.cruxcisupport.role.RoleEntity;
import com.yonyougov.devops.cruxcisupport.userrole.dto.service.UserPageByRoleRaramLikeDto;
import com.yonyougov.devops.cruxcisupport.userrole.dto.service.UserRoleByUserParamPageLikeDto;
import com.yonyougov.devops.cruxcisupport.userrole.vo.UserRoleByRoleParamPageLikeVo;
import com.yonyougov.devops.cruxcisupport.userrole.vo.UserRoleByUserParamPageLikeVo;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * t_user_role数据层实现
 */
@Repository
public class UserRoleDaoImpl extends BaseDaoImpl<UserRoleEntity, BigInteger> implements UserRoleDao {
    private final SqlSessionTemplate sqlSessionTemplate;

    public UserRoleDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    //<!--用户自定义代码开始-->

    @Override
    public int countByUserParamPageLike(UserRoleByUserParamPageLikeDto userRoleByUserParamPageLikeDto) {
        String statement = UserRoleEntity.class.getName() + "Mapper.countByUserRoleLike";
        return sqlSessionTemplate.selectOne(statement, userRoleByUserParamPageLikeDto);
    }

    @Override
    public List<UserRoleByUserParamPageLikeVo> findByUserParamPageLike(UserRoleByUserParamPageLikeDto userRoleByUserParamPageLikeDto) {
        String statement = UserRoleEntity.class.getName() + "Mapper.findUserRolePageLike";
        return sqlSessionTemplate.selectList(statement, userRoleByUserParamPageLikeDto);
    }

    @Override
    public List<RoleEntity> findRolesByUserId(BigInteger userId) {
        String statement = UserRoleEntity.class.getName() + "Mapper.findRolesByUserId";
        return sqlSessionTemplate.selectList(statement, userId);
    }

    @Override
    public void addBatch(List<UserRoleEntity> userRoleEntities) {
        String statement = UserRoleEntity.class.getName() + "Mapper.addBatch";
        sqlSessionTemplate.insert(statement, userRoleEntities);
    }

    @Override
    public void deleteBatchUserRoleByIds(List<BigInteger> ids) {
        String statement = UserRoleEntity.class.getName() + "Mapper.deleteBatchUserRoleByIds";
        sqlSessionTemplate.insert(statement, ids);
    }

    @Override
    public int countByRoleParamPageLike(UserPageByRoleRaramLikeDto userPageByRoleRaramLikeDto) {
        String statement = UserRoleEntity.class.getName() + "Mapper.countByUser";
        return sqlSessionTemplate.selectOne(statement, userPageByRoleRaramLikeDto);
    }

    @Override
    public List<UserRoleByRoleParamPageLikeVo> findByRoleParamPageLike(UserPageByRoleRaramLikeDto userPageByRoleRaramLikeDto) {
        String statement = UserRoleEntity.class.getName() + "Mapper.findUserPageLikeByRoleId";
        return sqlSessionTemplate.selectList(statement, userPageByRoleRaramLikeDto);
    }

    //<!--用户自定义代码结束-->
}
